$(function () {
  
    var illnessId = getQueryString("illnessId");
    console.log(illnessId);
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/illness.do?method=findIllnessByIllnessId&illnessId="+illnessId,

        function (data) {
        	console.log(data)
         $("#illness_id").val(data[0].illnessId),
	     $("#user_id").val(data[0].userId),
	     $("#temperature").val(data[0].temperature),
         $("#adult_pest_num").val(data[0].adultPestNum),
         $("#larva_num").val(data[0].larvaNum),
         $("#egg_num").val(data[0].eggNum),
         $("#detail").val(data[0].detail),
         $("#phone_num").val(data[0].phoneNum),
         $("#user_name").val(data[0].userName)
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {

        $.post(
            "/citrusmonitor/illness.do?method=modify",
            {
                "illnessId": $("#illness_id").val(),
                "userId": $("#user_id").val(),
                "temperature": $("#temperature").val(),
                "adultPestNum": $("#adult_pest_num").val(),
                "larvaNum": $("#larva_num").val(),
                "eggNum": $("#egg_num").val(),
                "detail": $("#detail").val(),
                "phoneNum": $("#phone_num").val(),
                "userName": $("#user_name").val()
            },
           function(res){
                console.log(res);
                res = JSON.parse(res);
                if(res.status==1){
                    alert("信息提示修改成功");
                }else{
                    alert("信息提示修改失败");
                }}
        )
    })
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    console.log(reg );
    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}
